from dateutil import parser
import matplotlib.dates as mdates
import matplotlib.pyplot as plt
import numpy as numpy
import pandas as pd
import datetime

df_ferrara = pd.read_csv('main/ferrara_270615.csv')
df_milano = pd.read_csv('main/milano_270615.csv')
df_mantova = pd.read_csv('main/mantova_270615.csv')
df_ravenna = pd.read_csv('main/ravenna_270615.csv')
df_torino = pd.read_csv('main/torino_270615.csv')
df_asti = pd.read_csv('main/asti_270615.csv')
df_bologna = pd.read_csv('main/bologna_270615.csv')
df_piacenza = pd.read_csv('main/piacenza_270615.csv')
df_cesena = pd.read_csv('main/cesena_270615.csv')
df_faenza = pd.read_csv('main/faenza_270615.csv')


# 读取温度和日期数据
y1 = df_ravenna['temp']
x1 = df_ravenna['day']
y2 = df_faenza['temp']
x2 = df_faenza['day']
y3 = df_cesena['temp']
x3 = df_cesena['day']
y4 = df_milano['temp']
x4 = df_milano['day']
y5 = df_asti['temp']
x5 = df_asti['day']
y6 = df_torino['temp']
x6 = df_torino['day']

# 把日期从string类型转化为标准的datetime类型
day_ravenna = [parser.parse(x) for x in x1]
day_faenza = [parser.parse(x) for x in x2]
day_cesena = [parser.parse(x) for x in x3]
day_milano = [parser.parse(x) for x in x4]
day_asti = [parser.parse(x) for x in x5]
day_torino = [parser.parse(x) for x in x6]
'''
# 调用subplos()函数,重新定义fig,ax变量
fig, ax = plt.subplots()
plt.xticks(rotation=70)

hours = mdates.DateFormatter('%H:%M')
ax.xaxis.set_major_formatter(hours)

# 这里需要画出三根线,所以需要三组参数,'g'代表'green'(r-离海近,g-离海远)
ax.plot(day_ravenna, y1, 'r', day_faenza, y2, 'r', day_cesena, y3, 'r')
ax.plot(day_milano, y4, 'g', day_asti, y5, 'g', day_torino, y5, 'g')
'''

'''
收集 10 个城市的最高温和最低温，
用线性图表示气温最值点和离海远近之间的关系。
'''

# dis是一个装城市距离海边距离的列表
dist = [df_ravenna['dist'][0],
        df_cesena['dist'][0],
        df_faenza['dist'][0],
        df_ferrara['dist'][0],
        df_bologna['dist'][0],
        df_mantova['dist'][0],
        df_piacenza['dist'][0],
        df_milano['dist'][0],
        df_asti['dist'][0],
        df_torino['dist'][0]
        ]

# temp_max是一个存放每个城市最高温度的列表
temp_max = [df_ravenna['temp'].max(),
            df_cesena['temp'].max(),
            df_faenza['temp'].max(),
            df_ferrara['temp'].max(),
            df_bologna['temp'].max(),
            df_mantova['temp'].max(),
            df_piacenza['temp'].max(),
            df_milano['temp'].max(),
            df_asti['temp'].max(),
            df_torino['temp'].max()
            ]

# temp_min存放最低温度的列表
temp_min = [df_ravenna['temp'].min(),
            df_cesena['temp'].min(),
            df_faenza['temp'].min(),
            df_ferrara['temp'].min(),
            df_bologna['temp'].min(),
            df_mantova['temp'].min(),
            df_piacenza['temp'].min(),
            df_milano['temp'].min(),
            df_asti['temp'].min(),
            df_torino['temp'].min()
            ]
# print(temp_min)

# 先画出最高温度
fig, ax = plt.subplots()
ax.plot(dist, temp_max, 'ro')

plt.show()
